<template>
	<layout :loading="loading" curPage="menu" :title="data.id ? '修改菜单':'新增菜单'">

		<form class="layui-form" @submit="submit" data-action="/admin/menu/save" data-rediret="/pages/menu/menuList">

			<div class="layui-col-md6">
				
				<inputGroup name="x.name|菜单名称" title="菜单名称" :value="data.name"></inputGroup>
				
				<radioGroup title="菜单类型" :list="menuTypeList" :value="data.type" name="x.type|菜单类型" @change="chooseMenuType"></radioGroup>
				
				<block v-if="data.type == 1">
					<inputGroup v-if="data.type == 1" name="x.icon|图标" title="图标" :value="data.icon"></inputGroup>
					
					<inputGroup type="number" name="x.orderNum|排序|count|empty" title="排序" :value="data.orderNum" placeholder="选填"></inputGroup>
					
					<input type="hidden" name="x.parentId" value="0" style="display: none;">
					
				</block>
				<block v-else>
					
					<singleSelect v-if="data.type > 1" title="父级菜单" :list="parentMenuList" name="x.parentId" :value="data.parentId" titleKey="name" valueKey="id"></singleSelect>
					
					<textareaGroup @blur="inputBlur" :maxlength="100000" name="x.url|权限地址" title="权限地址" :value="data.url"></textareaGroup>
					
					<inputGroup name="x.pages|页面链接" title="页面链接" :value="data.pages" v-if="data.type == 2"></inputGroup>
					
					<inputGroup name="x.key|页面标识" title="页面标识" :value="data.key" v-if="data.type == 2"></inputGroup>
					
					<inputGroup type="number" name="x.orderNum|排序|count|empty" title="排序" :value="data.orderNum" placeholder="选填"></inputGroup>
				</block>

				<inputGroup name="x.saveLogUrl|日志路径|empty" title="日志路径" :value="data.saveLogUrl" placeholder="选填"></inputGroup>
				
			</div>

			<div class="layui-form-item">
				<div class="layui-input-block">
					<input type="hidden" name="x.id" :value="id" style="display: none;">
					<button class="layui-btn" form-type="submit">{{ !data.id ? '保存' : '修改'}}</button>
					<button class="layui-btn layui-btn-primary" form-type="reset">重置</button>
					<button class="layui-btn layui-btn-primary" @click="kit.goBack('index')">取消</button>
				</div>
			</div>
		</form>

	</layout>
</template>

<script>
	export default {
		data() {
			return {
				menuTypeList:[
					{title:"一级菜单",value:1},
					{title:"二级菜单",value:2},
					{title:"操作类",value:3}
				],
				loading: false,
				id : '' ,
				data : {
					type : 1 ,
					saveLogUrl : ""
				},
				parentMenuList : []
			}
		},
		onLoad(params) {
			this.id = params.id ;
		},
		onShow() {
			this.loadData();
		},
		methods: {
			
			inputBlur:function(e){
				var value = e.detail.value ;
				if(!!this.data.saveLogUrl || !value) return ;
				this.data.saveLogUrl = value ;
			},
			
			submit:function(e){
				this.form.submit(e);
			},
			
			chooseMenuType:function(type){
				this.data['type'] = type ;
				if(type > 1){
					var that = this ;
					var data = {
						type : this.data.type 
					} ;
					this.kit.get("/admin/menu/getParentList",data,function(res){
						that.parentMenuList = res.list ;	
					});
				}
			},
			
			loadData : function(e){
				if (!this.id) {
					return false ;
				}
				var that = this ;
				var data = {
					id : this.id 
				} ;
				this.kit.get("/admin/menu/info",data,function(res){
					that.parentMenuList = res.parentMenuList || [] ;	
					that.data = res.data ;	
				});
			}
		}
	}
</script>

<style>

</style>
